package com.rran.study.designpattern.behavioral.strategy;


import com.rran.study.designpattern.behavioral.strategy.enums.PayEnums;
import com.rran.study.designpattern.behavioral.strategy.model.PayContext;
import com.rran.study.designpattern.behavioral.strategy.strategy.PayStrategy;
import com.rran.study.designpattern.behavioral.strategy.factory.PayStrategySimpleFactory;

import java.math.BigDecimal;

/**
 * 策略模式+简单工厂实现。不符合开闭原则
 */
public class StrategyNewApplication {

    public static void main(String[] args) {

        PayContext payContext = new PayContext();
        payContext.setName("Rran");
        payContext.setPrice(new BigDecimal(200));
        payContext.setStrategy(PayEnums.ALI);

        PayStrategy payStrategy = PayStrategySimpleFactory.getPayStrategy(payContext.getStrategy().name());
        if (payStrategy == null) {
          throw new RuntimeException("未找到支付策略");
        }
        payStrategy.pay(payContext);
    }
}
